<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script src="js/axios.js"></script>
    <script>

        // get请求
        // 请求的 URL 地址
        var url = 'http://www.liulongbin.top:3006/api/get'
        // 请求的参数对象
        var paramsObj = { name: 'zs', age: 20 }
        // 调用 axios.get() 发起 GET 请求
        axios.get(url, { params: paramsObj }).then(function (res) {
            // res.data 是服务器返回的数据
            var result = res.data
            console.log(result)
        })

    </script>

    <script>
        // POST请求
        // 请求的 URL 地址
        var url = 'http://www.liulongbin.top:3006/api/post'
        // 要提交到服务器的数据
        var dataObj = { location: '北京', address: '顺义' }
        // 调用 axios.post() 发起 POST 请求
        axios.post(url, dataObj).then(function (res) {
            // res.data 是服务器返回的数据
            var result = res.data
            console.log(result)
        })
    </script>


    <script>
        // 直接使用axios发请求
        axios({
            method: 'GET',
            url: 'http://www.liulongbin.top:3006/api/get',
            params: { // GET 参数要通过 params 属性提供
                name: 'zs',
                age: 20
            }
        }).then(function (res) {
            console.log(res.data)
        })

        axios({
            method: 'POST',
            url: 'http://www.liulongbin.top:3006/api/post',
            data: { // POST 数据要通过 data 属性提供
                bookname: '程序员的自我修养',
                price: 666
            }
        }).then(function (res) {
            console.log(res.data)
        })
    </script>
</body>

</html>